#!/usr/bin/env bash
set -e

# SoX Resampler Library       Copyright (c) 2007-16 robs@users.sourceforge.net
# Licence for this file: LGPL v2.1                  See LICENCE for details.

rm -f CMakeCache.txt             # Prevent interference from any in-tree build

j=-j4
build=Release

for n in \
    cc: \
    clang: \
    arm-linux-gnueabi-gcc:Linux \
    x86_64-w64-mingw32-gcc:Windows \
    i686-w64-mingw32-gcc:Windows \
    ; do
  compiler=$(echo $n | sed 's/:.*//')
  system=$(echo $n | sed 's/.*://')
  dir=$build-$compiler
  which $compiler > /dev/null || echo $compiler not found && (
  echo "***" $dir
  mkdir -p $dir
    cd $dir
    cmake -DCMAKE_BUILD_TYPE=$build -DCMAKE_C_COMPILER=$compiler -DCMAKE_SYSTEM_NAME="$system" -DBUILD_SHARED_LIBS=OFF -DWITH_OPENMP=OFF ..
    make $j && [ /$system = / ] && ctest -j || true
    cd tests
    ../../tests/throughput-test && SOXR_THROUGHPUT_GAIN=.6 ../../tests/throughput-test 2 3 || true
  )
done
